package net.lab1024.sa.base.module.support.yuntuip.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.module.support.yuntuip.dao.YuntuIpDao;
import net.lab1024.sa.base.module.support.yuntuip.domain.entity.YuntuIpEntity;
import net.lab1024.sa.base.module.support.yuntuip.domain.form.YuntuIpAddForm;
import net.lab1024.sa.base.module.support.yuntuip.domain.form.YuntuIpQueryForm;
import net.lab1024.sa.base.module.support.yuntuip.domain.form.YuntuIpUpdateForm;
import net.lab1024.sa.base.module.support.yuntuip.domain.vo.YuntuIpVO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * chenyuqiang Service
 *
 * @Author chenyuqiang
 * @Date 2025-09-16 22:46:18
 * @Copyright 1
 */

@Service
public class YuntuIpService {

    @Resource
    private YuntuIpDao yuntuIpDao;

    /**
     * 分页查询
     */
    public PageResult<YuntuIpVO> queryPage(YuntuIpQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<YuntuIpVO> list = yuntuIpDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(YuntuIpAddForm addForm) {
        YuntuIpEntity yuntuIpEntity = SmartBeanUtil.copy(addForm, YuntuIpEntity.class);
        yuntuIpDao.insert(yuntuIpEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(YuntuIpUpdateForm updateForm) {
        YuntuIpEntity yuntuIpEntity = SmartBeanUtil.copy(updateForm, YuntuIpEntity.class);
        yuntuIpDao.updateById(yuntuIpEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        yuntuIpDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        yuntuIpDao.deleteById(id);
        return ResponseDTO.ok();
    }

    /**
     * 列表查询
     */
    public List<YuntuIpVO> listall() {
        return yuntuIpDao.listall();
    }

    public  void deleteall() {
        yuntuIpDao.deleteall();
    }   
}
